#include <iostream>
#include <string.h>
using namespace std;
const int N = 1010;
int n, V, v[N], w[N];
int dp[N];
int main()
{
 // 读⼊数据
 cin >> n >> V;
 for(int i = 1; i <= n; i++) 
 cin >> v[i] >> w[i];
 
 // 搞定第⼀问
 for(int i = 1; i <= n; i++)
 for(int j = v[i]; j <= V; j++)
 dp[j] = max(dp[j], dp[j - v[i]] + w[i]);
 
 cout << dp[V] << endl;
 // 第⼆问
 memset(dp, 0, sizeof dp);
 for(int j = 1; j <= V; j++) dp[j] = -1;
 for(int i = 1; i <= n; i++)
 for(int j = v[i]; j <= V; j++)
 if(dp[j]!=-1)
 dp[j] = max(dp[j], dp[j - v[i]] + w[i]);
 
 cout << (dp[V] < 0 ? 0 : dp[V]) << endl;
 return 0;
}